import Vue from 'vue';
import VueRouter from 'vue-router';
import HomeView from '../views/home/index.vue';

Vue.use(VueRouter);
const routes = [{
        path: '/',
        name: 'home',
        component: HomeView,
        meta: {
            title: '主页'
        },
    },
    //主页
    // {
    //     path: '/home',
    //     name: 'home',
    //     component: () => import('../views/home/index.vue'),
    //     meta: {
    //         title: '主页'
    //     },
    // },
    //login登录
    {
        path: '/Login',
        name: 'Login',
        component: () => import('../views/Login/index.vue'),
        meta: {
            title: '登录'
        },
        beforeEnter: (to, from, next) => {
            //保存跳转过来的页面路径
            to.query.enterPath = from.path;
            next()
        }
    },
   

];
// 解决路由重复点击问题跳转问题,控制台报错由路由守卫拦截重定向导致
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, resolve, reject) {
    if (resolve || reject) return originalPush.call(this, location, resolve, reject)
    return originalPush.call(this, location).catch((e) => {})
}


const router = new VueRouter({
    routes,
    linkActiveClass: 'current',
    // base: process.env.NODE_ENV === 'production' ? '/webpage' : '/',  //配置打包后的线上文件路径,此处和 vue.config.js 中的 publicPath 配置任选一个
})
//router 配置页面头部显示文字
router.beforeEach((to, from, next) => {
    document.title = to.meta.title;
    next();
})

export default router;
